package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.DtsUserService;
import com.qf.service.DtsUserAccountService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * author:z
 * time:2021/11/30 16:08
 * description:
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    DtsUserService userService;

    @Autowired
    DtsUserAccountService userAccountService;


    @RequestMapping("/approveAgency")
    public Object update(DtsUser user) {
        userService.update(user);
        return ResponseUtil.ok();
    }

    @RequestMapping("/detailApprove")
    public Object detailApprove(Integer id) {
        DtsUserAccount byId = userAccountService.findById(id);
        Map<String, Object> data = new HashMap<>();
        data.put("id", byId.getId());
        data.put("userId", byId.getUserId());
        data.put("remainAmount", byId.getRemainAmount());
        data.put("totalAmount", byId.getTotalAmount());
        data.put("createTime", byId.getCreateTime());
        data.put("modifyTime", byId.getModifyTime());
        data.put("settlementRate", byId.getSettlementRate());
        data.put("status", byId.getStatus());
        return ResponseUtil.ok(data);

    }


    //会员列表
    @RequestMapping("/list")
    public Object list(@RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                       @RequestParam(name = "limit", required = false, defaultValue = "20") Integer limit,
                       @RequestParam(name = "sort", required = false, defaultValue = "add_time") String sort,
                       @RequestParam(name = "order", required = false, defaultValue = "desc") String order,
                       String username,
                       String mobile) {
        IPage<DtsUser> iPage = userService.queryPage(page, limit, sort, order, username, mobile);
        Map<String, Object> data = new HashMap<>();
        data.put("total", iPage.getTotal());
        data.put("items", iPage.getRecords());
        return ResponseUtil.ok(data);

    }
}
